package net.bithappens.hnqe.query;

import java.util.Arrays;

import net.bithappens.hnqe.IllegalParamException;

public class LogicalOperation extends QueryTree{

	public enum Operator {
		NOT,
		AND, 
		OR; 
	}
	
	private Operator operator;
	
	private QueryTree[] parameters;
		
	private LogicalOperation(Operator operator, QueryTree... parameters){
		this.operator = operator;
		this.parameters = parameters;
	}
	
		
	public static LogicalOperation NOT(QueryTree param){
		return new LogicalOperation(Operator.NOT, param);
	}
	
	public static LogicalOperation AND(QueryTree... params) throws IllegalParamException{
		if(params.length < 2){
			throw new IllegalParamException("There must be at least 2 parameters");
		}
		return new LogicalOperation(Operator.AND, params);
	}
	
	public static LogicalOperation OR(QueryTree... params) throws IllegalParamException{
		if(params.length < 2){
			throw new IllegalParamException("There must be at least 2 parameters");
		}
		return new LogicalOperation(Operator.OR, params);
	}
	
	
	public Operator getOpeator(){
		return operator;
	}
	
	public QueryTree[] getParameters(){
		return parameters;
	}


	@Override
	public String toString() {
		return operator + Arrays.toString(parameters);
	}
	
}
